package com.app.acitivty;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.app.activity.R;
import com.app.data.InnItem;
import com.app.data.LineItem;
import com.app.data.ScenicItem;
import com.app.data.YouhuiItem;
import com.app.service.HttpCallBack;
import com.app.service.LineService;
import com.app.service.adapter.LineAdapter;
import com.app.utils.GlobalConstants;

/**
 * 线路列表
 * 
 * @author Administrator
 * 
 */
public class LineListActivity extends Activity  implements HttpCallBack,OnItemClickListener{
	
	private LineItem[] items=
		{
			new LineItem(R.drawable.line1, "丽江泸沽湖旅游 泸沽湖纯玩 金沙江二日游 摩梭民俗花楼恋歌 ", "出发时间：2012-06-01", "￥455起"), 
			new LineItem(R.drawable.line2, "云南丽江 泸沽湖 女儿国 婚俗游民俗特色三日游 体验走婚 纯玩团", "出发时间：2012-06-01", "￥718起"), 
			new LineItem(R.drawable.line3, "云南丽江旅游 泸沽湖 走婚族 纯玩三日 猪糟船 花楼恋歌 摩梭特色", "出发时间：2012-06-01", "￥780起"), 
			new LineItem(R.drawable.line4, "云南丽江旅游 玉龙雪山 牦牛坪一日游 含古维牦牛坪索道 印象丽江", "出发时间：2012-06-01", "￥455起"), 
			new LineItem(R.drawable.line1, "丽江泸沽湖旅游 泸沽湖纯玩 金沙江二日游 摩梭民俗花楼恋歌 ","出发时间：2012-06-01", "￥455起"), 
			new LineItem(R.drawable.line2, "云南丽江 泸沽湖 女儿国 婚俗游民俗特色三日游 体验走婚 纯玩团", "出发时间：2012-06-01", "￥718起"), 
			new LineItem(R.drawable.line3, "云南丽江旅游 泸沽湖 走婚族 纯玩三日 猪糟船 花楼恋歌 摩梭特色", "出发时间：2012-06-01", "￥780起")
		};
	
	ArrayList<LineItem> lines;
	private ArrayList<HashMap<String, String>> mLineListItems = null;

	private String[] mLineColumnNames = { "lineIcon", "lineName",
			"lineTransport", "linePrice" };

	private int[] mLineViewIds = { R.id.imgLineIcon, R.id.tvLineName,
			R.id.tvLineTransport, R.id.tvLinePrice };
	
	private ListView listview;
	private ProgressDialog progressDialog;
	
	private void initView(){
		listview=(ListView) findViewById(R.id.lvLineList);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.line_list);
		initView();
		mLineListItems = new ArrayList<HashMap<String, String>>();

		for (int i = 0; i < 7; i++) {
			LineItem li = items[i];
			mLineListItems.add(addItem(li));
		}

		ListAdapter laLine = new SimpleAdapter(this, mLineListItems,
				R.layout.line_list_item, mLineColumnNames, mLineViewIds);

		//listview.setAdapter(laLine);
		LineService lineService = new LineService(this);
		lineService.execute("");
		progressDialog = new ProgressDialog(this);
		progressDialog.setTitle("提示");
		progressDialog.setMessage("读取数据中...");
		progressDialog.setCancelable(false);
		progressDialog.setIndeterminate(true);
		progressDialog.show();
	}
	
	public static HashMap addItem(LineItem item) {
		HashMap<Object, Object> map = new HashMap<Object, Object>();
		map.put("lineIcon", item.getLineIcon());
		map.put("lineName", item.getLineName());
		map.put("lineTransport", item.getLineTransport());
		map.put("linePrice", item.getLinePrice());
		return map;
	}

	@Override
	public void hotelFinishLoad(int code, ArrayList<InnItem> list) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void lineFinishLoad(int code, ArrayList<LineItem> list) {
		if (code == 0) {
			lines = list;
			LineAdapter adapter = new LineAdapter(this, list);
			listview.setAdapter(adapter);
			listview.setOnItemClickListener(this);
		}
	}

	@Override
	public void ticketFinishLoad(int code, ArrayList<ScenicItem> list) {
		// TODO Auto-generated method stub
	
	}

	@Override
	public void youhuiFinishLoad(int code, ArrayList<YouhuiItem> list) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
		// TODO Auto-generated method stub
		LineItem item = lines.get(position);
		GlobalConstants.getInstance().setLineitem(item);
		
		Intent intent = new Intent(this, LineDetailActivity.class);
		startActivity(intent);
	}

}
